


<script type="text/javascript">
<!-- 
var currentPic = 1;
function updateBigPhoto(newPhotoNum,id) {
	document.masterPhoto.src = "http://02d2e0a.netsolhost.com/images/scratch/"+id+"-"+newPhotoNum+"-main.jpg";
	currentPic = newPhotoNum;
	return false;
}
-->
</script>			

<?php

function resize_photo($filename,$num,$id) 
//   Give the option to send in $dimension indicating the size you want
// For each photo, make main size and thumbnail size
{
	// The file
	$numTN=3;  // Number of thumnails
	$docRoot = './';  // couldn't use full URL in getimagesize (http://... so had to use this

	if (!$dimension) {  // if this wasn't sent in as a parameter
		$desired_width = 250;
	} else {
		$desired_width = $dimension;
	}


	// ****************************************
	//   Make main photo for image
	// ****************************************
	// Get new dimensions
	list($width, $height)  = getimagesize($docRoot .$filename);
	$factor = 	$desired_width/$width;
	if ($factor > 1) {	// don't resize a photo to be larger than it's original
		$factor =1;
		}
	$new_width = $width * $factor;
	$new_height = $height * $factor;

	// Resample http://us3.php.net/manual/en/function.imagecopyresampled.php
	$image_p = imagecreatetruecolor($new_width, $new_height);
	$image = imagecreatefromjpeg($docRoot.$filename);
	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

	$newImageName = $docRoot.'images/scratch/'.$id.'-'.$num.'-main.jpg';
	$urlImageName = 'http://www.kalamazooanimalrescue.org/images/scratch/'.$id.'-'.$num.'-main.jpg';

	// Output
	imagejpeg($image_p, $newImageName, 75);	// write to file (in same directory as the calling file)
//	$size = GetImageSize ($newImageName);
//	echo ("<IMG SRC='".$urlImageName. "' ".  $size[3] . " class=\"".$class."\" style='margin-right:10px'>");	


	// ****************************************
	//   Make thumbnail photo for image  
	// ****************************************
	$new_width=$new_width/$numTN;        //   thumbnails will be 1/numTN width of main even when main is smaller
	$new_height=$new_height/$numTN;
	$image_p = imagecreatetruecolor($new_width, $new_height);
	$image = imagecreatefromjpeg($docRoot.$filename);

	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	$newImageName = $docRoot.'images/scratch/'.$id.'-'.$num.'-tn.jpg';
	$urlImageName = 'http://www.kalamazooanimalrescue.org/images/scratch/'.$id.'-'.$num.'-tn.jpg';
	// Output
	imagejpeg($image_p, $newImageName, 75);	// write to file (in same directory as the calling file)
//	$size = GetImageSize ($newImageName);
//	echo ("<IMG SRC='".$urlImageName. "' ".  $size[3] . " class=\"".$class."\" style='margin-right:10px'>");	
	ImageDestroy($image_p);
	ImageDestroy($image);


}

function photoBlock($displaypet)
{
	if (preg_match('/^(D|d)/', $displaypet)){
	$type = "dogs";
	}
else if ((preg_match('/^(C|c)/', $displaypet)) || (preg_match('/^(SC|sc)/', $displaypet))){
	$type = "cats";
	}
else{
	echo("<p>Pet type error</p>");
	}
	
	$showing = @mysql_query("SELECT * FROM $type, volunteers
					WHERE
					$type.volunteer_id=volunteers.volunteer_id AND 
					$type.tagNum='$displaypet'");

	$num_rows = mysql_num_rows($showing);

	while ( $row = mysql_fetch_array($showing) ) {       // pull the record info on the pet
		$temp_id = $row["tagNum"];		// pet id number
		$pet_name = $row["pet_name"];	// pet name
		$thumbnail = $row["thumb"];		// thumbnail image
		$photo1 = $row["main"];			// main image
		$photo2 = $row["photo2"];
		$photo3 = $row["photo3"];
		}	// end while
	
	if ($type=="cats") {
		$path="images/cats/"; 
		} else { 
		$path="images/dogs/"; 
		}

	if ($photo2 or $photo3) {	// checking to see if there is more than one photo
		$multiple = 1;		// if only one, we won't display thumbnails
		} else {
		$multiple = 0;
		}

	$scratchPath='./images/scratch/';    // this is where the main and tn photos are placed
			

	$url='http://02d2e0a.netsolhost.com/images/scratch/';
	$mainImage1 = $url.$temp_id.'-'.'1-main.jpg';	
	$mainImage2 = $url.$temp_id.'-'.'2-main.jpg';
	$mainImage3 = $url.$temp_id.'-'.'3-main.jpg';
	$tnImage1 = $url.$temp_id.'-'.'1-tn.jpg';		
	$tnImage2= $url.$temp_id.'-'.'2-tn.jpg';
	$tnImage3= $url.$temp_id.'-'.'3-tn.jpg';

if ($photo1) {	// If there is no photo 1 we will stop (not looking to see if there are others)

	$fullpath = $path . $photo1;
	resize_photo($fullpath, 1,$temp_id);
	echo("    <div id=\"mainphoto\">" );
	echo("<table><tr> <td valign=\"top\" align=\"right\"> ");
	echo ("<img name='masterPhoto' src=\"" . $mainImage1 ."\" border='0' class='mainphoto'></a>");
	echo("</td></tr><tr> <td valign=\"top\" align=\"right\">");
	if ($multiple) {  // only print if we have more than one photo
	echo("<font size=\"-2\" face=\"Arial, Helvetica, sans-serif\">Click Thumbnails Below to View Above</font>");
		}
	echo("</td></tr></table>");
	echo("</div>");

// Start placing thumbnail images
	if ($multiple) {		// if there is more than one image, make thumbnails
	echo("    <div id=\"tnphoto\"> 
                        <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
                        	<tr><td valign=\"bottom\">");
	echo('<div class="float">');
	echo("<a href='".$tnImage1."' onClick='return updateBigPhoto($mainImage1,1); return false;'>");
	echo("</a>");

	echo("<a href='".$tnImage1."' onClick='return updateBigPhoto(1,$temp_id); return false;'>");
	echo("<img src=\"" . $tnImage1 ."\"  border='0' class='tnphoto'></a>");


	if ($photo2) {
		$image = $type.$temp_id.'-2.jpg';
		$fullpath = $path. $image;
		resize_photo($fullpath, 2,$temp_id);

		echo("<a href='".$tnImage2."' onClick='return updateBigPhoto(2,$temp_id); return false;'>");
		echo("<img src=\"" . $tnImage2 ."\"  border='0' class='tnphoto'></a>");

		}

	if ($photo3) {
		$image = $type.$temp_id.'-3.jpg';
		$fullpath = $path. $image;
		resize_photo($fullpath, 3,$temp_id);
		echo("<a href='".$tnImage3."' onClick='return updateBigPhoto(3,$temp_id); return false;'>");
		echo("<img src=\"" . $tnImage3 ."\"  border='0' class='tnphoto'></a>");
		echo("</a>");
		}

		echo("</div></td></tr></table></div>");

	} //endif $multiple

	} // end if Photo1    We would not put a photo block out if there is no #1

}    //end function                

?>